﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using QuanLyRapChieuPhim.DTO;
using QuanLyRapChieuPhim.BUS;

namespace QuanLyRapChieuPhim.GUI
{
    public partial class frmDangNhap : Form
    {
        public frmDangNhap()
        {
            InitializeComponent();
        }

        private void frmDangNhap_Load(object sender, EventArgs e)
        {
            Location = new Point(150, 250);
        }

        private void btnHuy_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void btnDangNhap_Click(object sender, EventArgs e)
        {
            if (!Check())
                return;
            else
            {
                TaiKhoanDTO DTO = new TaiKhoanBUS().GetFromName(txtTenDangNhap.Text);
                QuanLyRapChieu.UserID = DTO.MaTaiKhoan;
                QuanLyRapChieu.UserName = DTO.TenDangNhap;
                QuanLyRapChieu.UserKind = DTO.MaLoaiTaiKhoan;
                QuanLyRapChieu.IsFinished = true;
                Close();
            }
        }

        bool Check()
        {
            lbsao01.Visible = false;
            lbsao02.Visible = false;
            lbThongBao.Visible = false;


            if (txtTenDangNhap.Text == "")
            {
                lbsao01.Visible = true;
                txtTenDangNhap.Focus();
                return false;
            }
            if (txtMatKhau.Text == "")
            {
                lbsao02.Visible = true;
                txtMatKhau.Focus();
                return false;
            }
            if (new TaiKhoanBUS().CheckLogin(txtTenDangNhap.Text,txtMatKhau.Text) <= 0)
            {
                lbThongBao.Visible = true;
                txtTenDangNhap.Focus();
                return false;
            }
            return true;
        }

        private void txtMatKhau_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter )
            {
                btnDangNhap_Click(null,null);
            }
        }

    }
}
